﻿@using System.Text
@using OA.Model
@using OA.AspNetCore.Html
@model PageList<SimpleVoucher>
@{    
    string errorMsg = ViewBag.ErrorMsg;     
    Layout = "~/Areas/Member/Views/Shared/_Layout.cshtml";
}
@if (string.IsNullOrEmpty(errorMsg))
{
    CustomForm infoCustomForm = ViewBag.CustomForm;
    FormGroup infoFormGroup = ViewBag.FormGroup;
    string addTitle = "新增" + infoCustomForm.Name;
    ViewBag.Title = infoCustomForm.Name + "列表";
    <div class="layui-tab layui-tab-brief" lay-filter="user">
        <div class="layui-form layui-tab-content" id="LAY_ucm">
            <form action="" class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: auto; padding-right: 5px;">单据名称：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="keyWord" class="layui-input" value="" />
                        <input type="hidden" name="id" value="@ViewBag.CustomID" />
                    </div>
                    <button type="button" class="layui-btn searchButton">搜索</button>
                    <a class="layui-btn AddItem" lay-href="/Member/CustomForm/Add?id=@infoCustomForm.ID">@addTitle</a>
                </div>
            </form>
        </div>
        <table class="layui-table" lay-data="{url:'GetData?id=@ViewBag.CustomID', cellMinWidth: 80, page: true,limit:15}" id="resultList" lay-filter="resultList">
            <thead>
                <tr>
                    <th lay-data="{field:'No', width:100}">编号</th>
                    <th lay-data="{field:'Title'}">单据名称</th>
                    <th lay-data="{field:'StatusName', width:120}">状态</th>
                    <th lay-data="{width:240, align:'center', toolbar: '#barDemo'}">操作</th>
                </tr>
            </thead>
        </table>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-xs" lay-href="/Member/CustomForm/Show?formID={{d.ID}}&customID={{d.CustomFormID}}" lay-text="查看{{d.No}}">查看</a>
            {{# if(d.Status==0){ }}
            <a class="layui-btn layui-btn-xs" lay-href="/Member/CustomForm/Edit?itemID={{d.ID}}&id={{d.CustomFormID}}" lay-text="编辑{{d.No}}">编辑</a>
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="Sponsor" lay-data="{{d}}">发起审批</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="Delete" lay-data="{{d}}">删除</a>
            {{# } }}
        </script>
       

    </div>
}
else
{
    <p>@errorMsg</p>
}
<script type="text/javascript">
    layui.use(['table', 'element'], function () {
        var table = layui.table;
        table.on('tool(resultList)', function (obj) {
            var data = obj.data;
            if (obj.event === 'Sponsor') {
                layer.confirm('<p>您正在进行单据发起审批操作</p><p style="color:red;">单据号:' + data.No + '</p>', {
                    title: "发起审批确认",
                    btn: ['是的,我要发起审批', '不小心点错了'] //按钮
                }, function () {
                    $.getJSON("/Member/CustomForm/Sponsor", { formID: data.ID, customID: data.CustomFormID }, function (result) {
                        if (result.State == 200) {
                            layer.closeAll();
                            layer.msg('申请审批发起成功!');
                            $(".layui-laypage-btn")[0].click();
                        }
                        else {
                            layer.msg(result.Msg);
                        }
                    });
                }, function () {

                });
            }
            else if (obj.event === 'resultList') {
                layer.confirm('<p>您正在进行删除单据操作</p><p style="color:red;">单据号:' + data.No + '</p>', {
                    title: "删除确认",
                    btn: ['是的,我要删除该单据', '不小心点错了'] //按钮
                }, function () {
                    $.getJSON("/Member/CustomForm/Delete", { id: data.ID, cid: data.CustomFormID }, function (result) {
                        if (result.State == 200) {
                            layer.closeAll();
                            layer.msg('单据删除成功!');
                            $(".layui-laypage-btn")[0].click();
                        }
                        else {
                            layer.msg(result.Msg);
                        }
                    });
                }, function () {

                });
            }
        });
    });    
</script>
